package com.credithc.signature.manager;

import com.credithc.signature.common.utils.GeneralUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @desc: <br/>
 * @author: Jingbo Hu<br/>
 * @time：2019年09⽉12⽇<br/>
 * @version：v1.0.0<br>
 */
public class SemaphoreTemplateNo {

    public static void main(String[] args) {

        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 500; i++) {
            MakeTemplateNo makeTemplateNo = new MakeTemplateNo();
            executorService.execute(makeTemplateNo);
        }
        executorService.shutdown();
    }
}
class MakeTemplateNo implements Runnable{
    private static final Semaphore semaphore = new Semaphore(1);
    private static String templateNo = "QZ2019temp00001";

    @Override
    public void run() {

        try {
            String channelAlias = "temp";
            semaphore.acquire();
            String s = GeneralUtil.buildTemplateNo(templateNo, channelAlias);
            templateNo = s;
            System.out.println(s);
            semaphore.release();
        } catch (InterruptedException e) {
            System.out.println(e);
        }
    }
}
